<?php
/**
 * @date        <!-- phpDesigner :: Timestamp [07-07-2010 16:32:40] -->
 * @filesource  cms.check.php
 * @package     WebCms
 * @copyright	Copyright (C) 2010
 * @author      Sérgio 'Horizak' Alves
 */

// Sem acesso directo
defined('_WEXEC') or die('Restricted access');

// Verifica se a aplicação está em manutenção
if (file_exists(CACHE_P.'maintenance.tmp')) {
  $value = file_get_contents(CACHE_P.'maintenance.tmp');
  echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\">
<head>
  <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />
  <title>Maintenance | WebCms</title>
</head>
<body>
{$value}
</body>
</html>";
  exit;
}

// Verifica o directório da instalação
if (file_exists(INSTALL_P.'index.php')) {
  header("Refresh:3; Url=".INSTALL_U);
  echo '<div style="text-align:center;">You will be redirected to the setup page. If not, click <a href="'.INSTALL_U.'">here</a>.</div>';
  exit();
}

// Verifica o ficheiro de configuração
if (!file_exists(CFG_P.'configuration.php') || (filesize(CFG_P.'configuration.php') < 20)) {
  echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\">
<head>
  <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />
  <title>Error | WebCms</title>
</head>
<body>
<div style='text-align:center;'>No configuration file found and no installation code available. Exiting...</div>
</body>
</html>";
  exit;
}

// Verifica se o directório do cache e do smarty compile têm permissões de escrita
if (!is_writable(CACHE_P) || !is_writable(SMARTYC_P)) {
  echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\">
<head>
  <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />
  <title>Error | WebCms</title>
</head>
<body>
<p>The following directories must be writable by the web server:<br />
  ".CACHE_P."<br />
  ".SMARTYC_P."<br />
</p>
<p>Please correct by executing:<br />
  chmod 777 ".CACHE_P."<br />
  chmod 777 ".SMARTYC_P."<br />
  or the equivilent for your platform before continuing.
</p>
</body>
</html>";
  exit;
}
?>